package com.xl.studentpass.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.xl.studentpass.service.LikeAndFavoriteService;
import com.xl.studentpass.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: xl
 * @createTime: 2023/6/7 11:27:46
 * @program: student-pass
 * @e-mail: 2199396150@qq.com
 * @description:
 */
@Api(tags = "点赞收藏相关接口")
@RestController
@Slf4j
@RequestMapping("/favorite")
public class LikeAndFavoriteController {
    @Resource
    LikeAndFavoriteService likeAndFavoriteService;

    /**
     * @param communityId 帖子id
     * @param categoryId  <li>0 喜欢</li><li>1 收藏</li>
     */
    @PostMapping("/like")
    @ApiOperation("用户点赞")
    public R giveLikeAndFavorite(@RequestParam("communityId") Integer communityId,
                                 @RequestParam("categoryId") Integer categoryId) {
        log.info(this.getClass().getSimpleName() + "==============进入点赞界面");
        int userId = StpUtil.getLoginIdAsInt();
        return likeAndFavoriteService.giveLikeAndFavorite(communityId, userId, categoryId);
    }
}
